<template>
  <div :class="className">
    <!-- style -->
    <!--<div v-html="css"></div>-->

    <div class="fixed-box set-pc-style" :style="box_style">
      <!--悬浮按钮静态-->
      <div class="btn" :style="button_style" @click.stop="toUrl">{{title}}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["id", "datas", "styles"],
  data() {
    return {};
  },
  components: {},
  mounted() {},
  computed: {
    box_style() {
      const { button_size, over_bottom, margin_size } = this.datas;
      return `
        height: ${button_size}px;
        line-height: ${button_size}px;
        poposition: fixed;
        bottom: ${over_bottom}px;
        padding: 0 ${margin_size}px;
        box-sizing: border-box;
      `;
    },
    button_style() {
      const { preview_color, text_size, text_color, radius_size } = this.datas;
      return `
        border-radius: ${radius_size}px;
        overflow: hidden;
        font-size: ${text_size}px;
        color: ${text_color};
        background-color: ${preview_color.color};
        background-image: url(${preview_color.isColor == 2 ? preview_color.image : ""});
        background-size: 100% auto;
        bakcground-position: center;
        `;
    },
    /** 标题 */
    title() {
      return this.datas.title || '';
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    }
  },

  methods: {
    toUrl() {
      let item = this.datas.link;
      let params = {};
      if(item.is_minApp == 2 && this.fun.isWindVane()) {
        // "appId":"小程序appid",
        params = { target: `wxmp://jumpmp:{"originId": ${item.gh_id},"path":${item.minApp_link},"extraData":{"from":"app"}}`  };
        window.WindVane.call('SBase','navigationTo',params,function(e){
          alert('navigationTo success:'+JSON.stringify(e));
        },function(e){
          alert('navigationTo failure:'+JSON.stringify(e));
        });
        return;
      }
      if(item.is_h5 == 2 && this.fun.isApp()) {
        YDB.MiniWX(item.gh_id, item.minApp_link);
        return;
      }
      if(item.is_h5 == 2 &&  this.fun.isCPS()) {
        let json = {
          mini_route: item.minApp_link,
          mini_id: item.gh_id,
        };
        if (this.fun.isIosOrAndroid() === "ios") {
          miniWXIOS({ body: "miniWXIOS", json: JSON.stringify(json) });
        } else {
          miniWXAndroid(JSON.stringify(json));
        }
        return;
      }

      if(item.is_h5 == 7) {
        if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
          let json = { name: 'task' };
          if (this.fun.isIosOrAndroid() === "ios") {
            toUrlIOS({ body: "toUrlIOS", json: JSON.stringify(json) });
          } else {
            toUrlAndroid(JSON.stringify(json));
          }
        }else if(item.link) {
          window.location.href = item.link;
        }
      }else if (item.is_h5 == 1 && item.link) {
        if(this.fun.isWindVane()) {
          params = { target: item.link };
          window.WindVane.call('SBase','navigationTo',params,function(e){
            alert('navigationTo success:'+JSON.stringify(e));
          },function(e){
            alert('navigationTo failure:'+JSON.stringify(e));
          });
          return;
        }
        window.location.href = item.link;
      }
    },
  }
};
</script>

<style lang="scss" scoped>
  // 默认
  .component-wrapper {
    width: 100%;
  }

  .fixed-box {
    width: 100%;
    position: fixed;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;

    .btn {
      width: 100%;
      height: 100%;
      text-align: center;
    }
  }

</style>
